import lejos.nxt.*;

//NOT IN CURRENT USE
/**
 * A class that handles the touch sensor of the robot.
 *  
 * @author sava
 * 
 */
public class TSensor {
	private static boolean doOpen = false;
	private static boolean doClose = false;
	private static boolean stateS4 = false;
	private static TouchSensor ts4 = new TouchSensor(SensorPort.S4);
	private static int nCountTouches = 0;

	/**
	 * Initiates the listener that counts number of touches.
	 */
	public static void listen() {

		stateS4 = ts4.isPressed(); // initiate.
		SensorPort.S4.addSensorPortListener(new SensorPortListener() { // Add
																		// listener
					public void stateChanged(SensorPort arg0, int oldValue,
							int newValue) {
						boolean curState = ts4.isPressed();
						if (curState != stateS4) {
							stateS4 = curState;
							if (stateS4) {
								nCountTouches++;
								if ((nCountTouches % 2) == 0)
									doOpen = true;
								else
									doClose = true;
							}
						}

					}
				});

	}

	/**
	 * Returns how many touches the TSensor has registered.
	 * @return The number of touches.
	 */
	public static int nTouches() {
		return nCountTouches;
	}

	/**
	 * Resets the number of touches registered to 0.
	 */
	public static void resetTouches() {
		nCountTouches = 0;
	}
}
